﻿using System;
using System.Collections.Generic;
using System.Text;

namespace EasyFramework._CodeTip
{   
    /// <summary>
    /// 排序类型：升/降
    /// </summary>
    [Serializable]
    public enum OrderMode
    {
        Asc,
        Desc
    }

    class Enum
    {
        /// <summary>
        /// 遍历枚举的所有元素
        /// </summary>
        public void ForeachEnum()
        {
            // 遍历名称
            foreach (string str in System.Enum.GetNames(typeof(OrderMode)))
            {
                Console.WriteLine(str);
            }

            // 遍历值
            foreach (OrderMode om in System.Enum.GetValues(typeof(OrderMode)))
            {
                Console.WriteLine(om);
            }
        }

        /// <summary>
        /// 将元素字符串转换为对应的枚举元素
        /// </summary>
        /// <param name="element">Asc or Desc</param>
        /// <returns></returns>
        public OrderMode ConvertEnum(string element)
        {
            return (OrderMode)System.Enum.Parse(typeof(OrderMode), element);
        }
    }
}
